package com.yunwaikeji.gy_tool_library.utils;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

public class GYAnimationUtils {
    private Context context;

    public GYAnimationUtils(Context context) {
        this.context = context;
    }

    private static GYAnimationUtils GYAnimationUtils;

    public static GYAnimationUtils getInstance(Context context) {
        if (GYAnimationUtils == null) {
            GYAnimationUtils = new GYAnimationUtils(context);
        }
        return GYAnimationUtils;
    }

    private long time = 200;

    public void animationFloat(View view, float fromXValue, float toXValue, float fromYValue, float toYValue) {
        TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, fromXValue, Animation.RELATIVE_TO_SELF, toXValue,
                Animation.RELATIVE_TO_SELF, fromYValue, Animation.RELATIVE_TO_SELF, toYValue);
        //执行后是否停留在执行后的位置
        translateAnimation.setFillAfter(true);
        //执行后是否停留在初始位置
//            translateAnimation.setFillBefore(false);
        //动画重复执行次数
//            translateAnimation.setRepeatCount(0);
        //动画执行前等待时间
//            translateAnimation.setStartOffset(0);
        //动画执行时间
        translateAnimation.setDuration(time);
        view.startAnimation(translateAnimation);
    }

    public void animationPx(View view, float fromXValue, float toXValue, float fromYValue, float toYValue) {
        TranslateAnimation translateAnimation = new TranslateAnimation(fromXValue, toXValue,
                fromYValue, toYValue);
        //执行后是否停留在执行后的位置
        translateAnimation.setFillAfter(true);
        //执行后是否停留在初始位置
//            translateAnimation.setFillBefore(false);
        //动画重复执行次数
//            translateAnimation.setRepeatCount(0);
        //动画执行前等待时间
//            translateAnimation.setStartOffset(0);
        //动画执行时间
        translateAnimation.setDuration(time);
        view.startAnimation(translateAnimation);
    }
}
